package Lab09.Q8;

class NTException extends Exception {
    public NTException(double x, double y, double z) {
        super(x + " " + y + " " + z + "无法构成三角形");
    }
}

public class Triangle {
    double x, y, z;

    public Triangle(double x, double y, double z) throws NTException {
        this.x = x;
        this.y = y;
        this.z = z;
        checkException();
    }

    public double getArea() {
        double p = (this.x + this.y + this.z) / 2;
        return Math.sqrt(p * (p - this.x) * (p - this.y) * (p - this.z));
    }

    public void showInfo() {
        System.out.println("x: " + this.x + "\ny: " + this.y + "\nz: " + this.z);
    }

    public void checkException() throws NTException {
        if (x + y <= z || x + z <= y || z + y <= x) {
            throw new NTException(x, y, z);
        }
    }
}
